package com.fcscs.cservice.client.main.configuration.inroomdining;

import com.extjs.gxt.ui.client.event.ButtonEvent;
import com.extjs.gxt.ui.client.event.SelectionListener;
import com.extjs.gxt.ui.client.store.ListStore;
import com.extjs.gxt.ui.client.widget.HorizontalPanel;
import com.extjs.gxt.ui.client.widget.Label;
import com.extjs.gxt.ui.client.widget.LayoutContainer;
import com.extjs.gxt.ui.client.widget.VerticalPanel;
import com.extjs.gxt.ui.client.widget.form.ComboBox.TriggerAction;
import com.extjs.gxt.ui.client.widget.form.TextField;
import com.extjs.gxt.ui.client.widget.layout.ColumnData;
import com.extjs.gxt.ui.client.widget.layout.ColumnLayout;
import com.fcscs.core.gwt.common.CoreConstants;
import com.fcscs.core.gwt.common.FormSubmitListener;
import com.fcscs.core.gwt.common.ui.BaseFormDialog;
import com.fcscs.core.gwt.common.ui.FcsFields.EasyClearCombobox;
import com.fcscs.core.gwt.common.ui.FcsFields.FormButton;
import com.fcscs.core.gwt.common.ui.FcsFormPanel;
import com.fcscs.cservice.client.common.CServiceConstants;
import com.fcscs.cservice.client.common.model.configuration.inroomdining.TransactionType;
import com.fcscs.cservice.client.common.model.configuration.inroomdining.TransactionTypeModelData;

public class TransactionTypeDialog extends BaseFormDialog<TransactionTypeModelData> {
	private static TransactionTypeDialog INSTANCE;
	private MyFormPanel myFormPanel;
	private HorizontalPanel hp1;
	private LayoutContainer lc1;
	private TextField<String> transField;
	private HorizontalPanel hp2;
	private LayoutContainer lc2;
	private TextField<String> codeField;
	private HorizontalPanel hp3;
	private LayoutContainer lc3;
	private EasyClearCombobox<TransactionTypeModelData> revenueCombox;
	private ListStore<TransactionTypeModelData> revenueStore;
	private FormButton saveBtn;
	private FormButton cancelBtn;
	private boolean isAdd;

	public static TransactionTypeDialog getInstance(boolean add) {

		if (null == INSTANCE) {
			INSTANCE = new TransactionTypeDialog();
		}
		INSTANCE.isAdd = add;
		INSTANCE.setHeader();
		return INSTANCE;
	}

	@Override
	public void hide() {
		super.hide();
	}

	public void setHeader(){
		if (isAdd) {
			INSTANCE.setHeading(CoreConstants.CORE_MESSAGES.operation(CoreConstants.CORE_CONSTANTS.add(),
					CServiceConstants.CSERVICE_CONSTANTS.transactionType()));
		}else {
			updatePanel();
			INSTANCE.setHeading(CoreConstants.CORE_MESSAGES.operation(CoreConstants.CORE_CONSTANTS.edit(),
					CServiceConstants.CSERVICE_CONSTANTS.transactionType()));
		}
	}
	
	private TransactionTypeDialog() {
		myFormPanel = new MyFormPanel(null);
		add(myFormPanel);
		setSize(450, 200);
	}

	public class MyFormPanel extends FcsFormPanel<TransactionType> {

		protected MyFormPanel(FormSubmitListener<TransactionType> l) {
			super(l);
			setHeaderVisible(false);

			VerticalPanel vp = new VerticalPanel();
			vp.setSpacing(5);
			vp.setId("TransactionTypeDialog_vp");

			hp1 = new HorizontalPanel();
			hp1.setId("TransactionTypeDialog_hp1");
			vp.add(hp1);

			lc1 = new LayoutContainer();
			lc1.setId("TransactionTypeDialog_lc1");
			lc1.setLayout(new ColumnLayout());
			hp1.add(lc1);

			Label transLabel = new Label(CServiceConstants.CSERVICE_CONSTANTS.transactionType()
					+ CServiceConstants.FIELD_SEP);
			transLabel.setId("TransactionTypeDialog_transLabel");
			lc1.add(transLabel, new ColumnData(150));

			transField = new TextField<String>();
			transField.setId("TransactionTypeDialog_transField");
			lc1.add(transField, new ColumnData(200));

			hp2 = new HorizontalPanel();
			hp2.setId("TransactionTypeDialog_hp2");
			vp.add(hp2);

			lc2 = new LayoutContainer();
			lc2.setId("TransactionTypeDialog_lc2");
			lc2.setLayout(new ColumnLayout());
			hp2.add(lc2);

			Label codeLabel = new Label(CoreConstants.CORE_CONSTANTS.code() + CServiceConstants.FIELD_SEP);
			codeLabel.setId("TransactionTypeDialog_actionLabel");
			lc2.add(codeLabel, new ColumnData(150));

			codeField = new TextField<String>();
			codeField.setId("TransactionTypeDialog_codeField");
			lc2.add(codeField, new ColumnData(200));

			hp3 = new HorizontalPanel();
			hp3.setId("TransactionTypeDialog_hp3");
			vp.add(hp3);

			lc3 = new LayoutContainer();
			lc3.setId("TransactionTypeDialog_lc2");
			lc3.setLayout(new ColumnLayout());
			hp3.add(lc3);

			Label revenueLabel = new Label(CServiceConstants.CSERVICE_CONSTANTS.revenue() + CServiceConstants.FIELD_SEP);
			revenueLabel.setId("TransactionTypeDialog_revenueLabel");
			lc3.add(revenueLabel, new ColumnData(150));

			revenueCombox = new EasyClearCombobox<TransactionTypeModelData>();
			revenueCombox.setId("TransactionTypeDialog_revenueCombox");
			revenueStore = new ListStore<TransactionTypeModelData>();
			revenueCombox.setStore(revenueStore);
			revenueCombox.setDisplayField(CoreConstants.FULLTNAME);
			revenueCombox.setTriggerAction(TriggerAction.ALL);
			revenueCombox.setForceSelection(true);
			lc3.add(revenueCombox, new ColumnData(200));

			saveBtn = new FormButton(CoreConstants.CORE_CONSTANTS.save());
			saveBtn.setId("TransactionTypeDialog_saveBtn_Id");
			getButtonBar().add(saveBtn);

			cancelBtn = new FormButton(CoreConstants.CORE_CONSTANTS.cancel());
			cancelBtn.setId("TransactionTypeDialog_cancelBtn_Id");
			cancelBtn.addSelectionListener(new SelectionListener<ButtonEvent>() {

				@Override
				public void componentSelected(ButtonEvent ce) {
					TransactionTypeDialog.this.hide();
					cancelBtn.removeStyleName(CoreConstants.CSS_FORM_BUTTON_FOCUS);
				}
			});
			getButtonBar().add(cancelBtn);

			add(vp);

		}

		@Override
		public void setFocus() {

		}

		@Override
		public void updateForm(TransactionType entity) {
			// TODO Auto-generated method stub

		}

		@Override
		public void populateEntity(TransactionType entity) {
			// TODO Auto-generated method stub

		}

	}
	
	//TODO
	public void updatePanel(){
		transField.setValue("demo");
		codeField.setValue("a12345");
		revenueCombox.setRawValue("demo");
	}

	@Override
	protected FcsFormPanel<TransactionTypeModelData> getFormPanel() {
		return null;
	}

}
